<?php
include_once("db.inc");
$username = $_REQUEST["username"];
$page = $_REQUEST["page"];

$row_number = 10;
$start = $row_number*$page;

$return = "";
$sql = "select * from sanpham where doanhnghiep='$username' limit $start,$row_number"; 
$result = mysql_query($sql);
$return = $return."<table border=\"0\" cellpadding=\"1\" width=\"100%\">
<tr id=\"tr\">
<td align=\"center\" style=\"cursor:pointer\"><b>Tên sản phẩm</b></td>
<td align=\"center\" style=\"cursor:pointer;width:140px\"><b>Giá</b></td>
</tr>";
$n = 0;
while ($row = mysql_fetch_array($result))
{
	$n++;
	$MaSanPham = $row["masanpham"];
	$TenSanPham = $row["tensanpham"];
	$Gia = $row["gia"];
	$HangSanXuat = $row["hangsanxuat"];
	$BaoHanh = $row["baohanh"];		
	$URL = $row["hinhanh"];
     //hiển thị ra trình duyệt
    $return =  $return."<tr";
	if($n%2==0) $return = $return." bgcolor='#EEEEEE'";
	$return = $return.">
    <td height=\"34px\" style=\"cursor:pointer\" onclick=\"showInfo('$MaSanPham')\">$TenSanPham</td>
	<td height=\"34px\" style=\"cursor:pointer\">".number_format($Gia,0,',','.')." VND</td>
	<td class=\"deleteIcon\" onclick=\"deleteSanPham('$MaSanPham')\"></td>
	<td class=\"updateIcon\" onclick=\"showUpdateSanPhamForm('$MaSanPham','$TenSanPham',$Gia,'$HangSanXuat',$BaoHanh,'$URL')\"></td>
	</tr>";
}
$return = $return."</table>";
$sql = "select masanpham from sanpham where doanhnghiep='$username'";
if(mysql_num_rows(mysql_query($sql))%$row_number == 0)
	$page_number = mysql_num_rows(mysql_query($sql))/$row_number;
	else $page_number = floor(mysql_num_rows(mysql_query($sql))/$row_number)+1;
if($page_number > 1)
{
	$return = $return."<p style=\"text-align:center\">";
	if($page != 0)
		$return = $return."<img src=\"images/prev2.jpg\" onclick=\"showSanPham_Member(0)\" style=\"cursor:pointer\">&nbsp;&nbsp;";
		else $return = $return."<img src=\"images/prev2.jpg\" style=\"cursor:pointer\">&nbsp;&nbsp;";
	if($page != 0)
		$return = $return."<img src=\"images/prev.jpg\" onclick=\"showSanPham_Member($page-1)\" style=\"cursor:pointer\">&nbsp;&nbsp;";
		else $return = $return."<img src=\"images/prev.jpg\" style=\"cursor:pointer\">&nbsp;&nbsp;";
	for($i = 0; $i < $page_number; ++$i)
	{
		if($i == $page)
		$return = $return."<b onclick=\"showSanPham_Member($i)\" style=\"cursor:pointer;color:#F00\" class=\"textPage\">".($i+1)."&nbsp;</b>";
		else $return = $return."<b onclick=\"showSanPham_Member($i)\" style=\"cursor:pointer\" class=\"textPage\">".($i+1)."&nbsp;</b>";
	}
	if($page != $page_number-1)
		$return = $return."<img src=\"images/next.jpg\" onclick=\"showSanPham_Member($page+1)\" style=\"cursor:pointer\">&nbsp;&nbsp;";
		else $return = $return."<img src=\"images/next.jpg\" style=\"cursor:pointer\">&nbsp;&nbsp;";
	if($page != $page_number-1)
		$return = $return."<img src=\"images/next2.jpg\" onclick=\"showSanPham_Member($page_number-1)\" style=\"cursor:pointer\"></p>";
		else $return = $return."<img src=\"images/next2.jpg\" style=\"cursor:pointer\"></p>";
}
$return = $return."<div id=\"SanPhamInfo\"></div>";
echo $return;
?>